using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ScreenShooter
{
    public partial class CaptureAreaForm : Form
    {
        private Point firstPosition;
        private Point lastPosition;
        private bool isDragged = false;
        private MainForm mainform;


        public CaptureAreaForm(MainForm mainform)
        {
            InitializeComponent();
            this.mainform = mainform;
            this.mainform.ResetPoints();
        }

        private void CaptureAreaForm_MouseDown(object sender, MouseEventArgs e)
        {
            if(e.Button == MouseButtons.Left)
                firstPosition = e.Location;
        }

        private void CaptureAreaForm_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && isDragged)
            {
                lastPosition = e.Location;
                mainform.SetPoint(GetRegion());
                Close();
            }
        }

        public Point[] GetRegion()
        {
            Point[] points = new Point[2];
            points[0] = firstPosition;
            points[1] = lastPosition;
            return points;
        }

        private void CaptureAreaForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                isDragged = true;
        }
    }
}